<!--
  * 时间：2024/12/25
  * 作者：刘岩
  * 描述：查看设备弹窗
-->
<template>
  <el-dialog title="查看设备" :visible.sync="open" width="80%" append-to-body>
    <el-table v-loading="loading" :data="equipmentList">
      <el-table-column label="设备名称" align="center" prop="cn" />
      <el-table-column label="所属区域" align="center" prop="regionName" />
      <el-table-column label="设备状态" align="center" prop="online">
        <template slot-scope="scope">
          <span>{{ scope.row.online === 0 ? '离线' : scope.row.online === 1 ? '在线' : '' }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </el-dialog>
</template>

<script>
import { listEquipment } from "@/api/deviceManage";

export default {
  name: "deviceDialog",
  props: {
    // 弹窗状态
    status: {
      type: Boolean,
      default: false
    },
    // code
    code: {
      type: String,
      default: null
    }
  },
  data() {
    return {
      open: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 设备数据
      equipmentList: [],
    }
  },
  watch: {
    status(val) {
      if (val) {
        this.open = val;
        this.getList();
      }
    },
    open(val) {
      this.$emit('update:status', val);
    }
  },
  methods: {
    /**
     * 时间：2024/12/25
     * 作者：刘岩
     * 功能：请求数据
     */
    getList() {
      this.loading = true;
      listEquipment({
        includeSubNode: '1', // 是否包含下级，1包含，0不包含（若regionId为空，则该参数不起作用）
        pageNo: this.queryParams.pageNum,
        pageSize: this.queryParams.pageSize,
        regionId: this.code
      }).then(res => {
        let data = JSON.parse(res.msg);
        this.equipmentList = data.data.list;
        this.total = data.data.total;
        this.loading = false;
      });
    }
  }
}
</script>

<style scoped lang="scss">

</style>
